Solved

duplication insert into SQL

Posted on 2013-02-06
3
299 Views
Last Modified: 2013-02-06
Hay im getting error with line 40 can i get some help its to stop dupication incert into SQL

<?php 

// Read values from form using $_POST (safest) 


$fname=$_POST["vname"]; 


// Connect to server 
// Replace username and password by your details  

$db = @mysql_connect("localhost","root","iqonr301"); 
if (!$db) 
{ 
        do_error("Could not connect to the server"); 
} 


// Connect to the database 
// Note that your database will be called username 

@mysql_select_db("test",$db)or do_error("Could not connect to the database"); 

// Run query 

$sql="INSERT INTO teacher (name) values ('$fname')"; 
$dupesql = "SELECT * FROM table where (name = '$fname')";

$duperaw = mysql_query($dupesql);

if (mysql_num_rows($duberaw) > 0) {
  //your code ...
}
if (mysql_query($sql,$db)) 
{ 
        echo "The following Teacher"; 
        echo "<br>Record: $fname  has been added to          
        database.<p>"; 
} 
else 
{ 
        do_error("Failed to add record"); 
} 

function  do_error($error) 
{ 
        echo  $error; 
        die; 
} 

?>

Open in new window



Notice: Undefined variable: duberaw in C:\xampp\htdocs\insert.php on line 40
 
Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\insert.php on line 40
 Failed to add record
0
Comment
Question by:paddy086
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 43

Assisted Solution

by:Chris Stanyon
Chris Stanyon earned 334 total points
ID: 38859587
Line 29 says $duperaw
line 31 says $duberaw

check your spelling :)
0
 
LVL 42

Assisted Solution

by:sedgwick
sedgwick earned 166 total points
ID: 38859618
change line 29 to:
$duperaw = mysql_query($dupesql, $db);

Open in new window

0
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 334 total points
ID: 38859620
Line 26 is INSERTing from a table called 'teacher'
Line 27 is SELECTing from a table caled 'table'
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question