Unable to INSERT any records in MYSQL from PHP -
so trying develop app , need api, trying php in order pass variables app mysql. trying $_get first in order see if works fine. tried pass variables database through mysql workbench , app , worked fine. but, when emptied table , tried again didn't work! guessing loop doesn't respond fact table empty(?)
this code checks email , username if exists , if not insert variables:
$result = 'notset'; $query=mysql_query("select * project"); while ($row = mysql_fetch_assoc($query)) { if(strcmp($row['email'],$email)==0){ //strcmp uses 2 strings , returns integer, if 0 no differences if more 0 there $result = 'email exists'; }else{ if(strcmp($row['username'],$username)==0){ $result = 'username exists'; }else{ //encryption $insert = mysql_query("insert project values ('$userid', '$fullname','$username','$password','$course','$year','$age','$email')"); $result = 'registered'; session_start(); $session = session_id(); $session['username']=$username; } } }
any ideas??
your table empty. $query returning false. because of loop not executed. should change code this:
if($query){ while(){ //check username , email } } else{ // execute insert query }
can try code:
$result = 'notset'; $query = mysql_query("select * project email = '$email' or username = '$username' "); if(mysql_num_rows($query) === 0 ){ $insert = mysql_query("insert project values ('$userid', '$fullname','$username','$password','$course','$year','$age','$email')"); $result = 'registered'; session_start(); $session = session_id(); $session['username']=$username; } else{ $result = 'username or email exists'; }
Comments
Post a Comment