Solved

duplication insert into SQL

Posted on 2013-02-06
3
296 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Find RGB colors from a screen. 2 41
e commerce steps shown instead of self testing 2 56
Google Recaptcha 13 52
php non-object 7 28
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

734 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